﻿//**********************************************************
//Copyright(C)2010 By 波特商网公司 版权所有。
//
//文件名：
//文件功能：首页Form
//
//创建标识：齐李平 || 2011-03-24
//
//修改标识：
//修改描述：
//**********************************************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Hmc.IM.Common.Forms;
using Hmc.IM.Common.Base;
using Hmc.IM.Client.Core;
using Hmc.IM.Common;

namespace Hmc.IM.Client
{
    /// <summary>
    /// 首页
    /// </summary>
    public partial class HomeForm : FrameForm
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public HomeForm()
        {
            PowerId = 0;
            InitializeComponent();
        }

        /// <summary>
        /// 窗体加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HomeForm_Load(object sender, EventArgs e)
        {
            lbUser.Text = string.Format("{0},您好！", LoginUserEntity.RealName);
            flpPanel1.BeginInvoke(new Action(InitData));
        }

        private void InitData()
        {
            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += (sender, e) =>
                {
                    try
                    {
                        //List<SystemMessageEntity> list = ServiceInvokeHelper<StoreContractsClient>.Invoke(c => c.GetNewSystemMessageByUserId(LoginUserEntity.Token, 6, LoginUserEntity.SystemUserId));
                        //worker.ReportProgress(1, list);
                        //list = ServiceInvokeHelper<StoreContractsClient>.Invoke(c => c.GetTodayMessage(LoginUserEntity.Token, LoginUserEntity.OrganizationId));
                        //worker.ReportProgress(2, list);
                    }
                    catch (Exception ex)
                    {
                        //Recorder.Write(ex);
                    }
                };
            worker.ProgressChanged += (sender, e) =>
                {
                    //List<SystemMessageEntity> list = e.UserState as List<SystemMessageEntity>;
                    //if (list != null && list.Count > 0)
                    //{
                    //    foreach (SystemMessageEntity item in list)
                    //    {
                    //        if (e.ProgressPercentage == 1)
                    //            AddItem(item, flpPanel1);
                    //        else if (e.ProgressPercentage == 2)
                    //            AddItem(item, flpPanel2);
                    //    }
                    //}

                };
            worker.WorkerReportsProgress = true;
            worker.RunWorkerAsync();
        }

        //private void AddItem(SystemMessageEntity item,Control ctl)
        //{
        //    Label lb = new Label();
        //    lb.AutoEllipsis = true;
        //    lb.ForeColor = System.Drawing.Color.FromArgb(75, 75, 75);
        //    lb.Image = global::Hmc.IM.Client.Properties.Resources.home_lg1;
        //    lb.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
        //    lb.Margin = new System.Windows.Forms.Padding(10, 7, 3, 0);
        //    lb.Name = item.MessageId.ToString();
        //    lb.Size = new System.Drawing.Size(flpPanel1.Width - 2, 15);
        //    if (ctl == flpPanel1)
        //        lb.Text = string.Format("  [{0}]{1}", item.CreateTime.ToString("yyyy-MM-dd"), item.Content);
        //    else
        //        lb.Text = string.Format("  {0}", item.Content);
        //    ctl.Controls.Add(lb);
        //}
    }
}
